<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <meta name="theme-color" content="#34495e">
  <title>rem适配移动页面-js方法 | 烟波</title>
  <link rel="alternate" href="path/of/rss" type="application/atom+xml">
  <link rel="shortcut icon" type="image/ico" href="/favicon.ico">
  <link rel="stylesheet" href="/my-blog/css/style.css">
  

  

  

  

</head>

<body>
  <div class="mobile-header">
    <span><i class="iconfont icon-turnon" id="mobile-nav-toggle"></i></span>
    <div class="mobile-logo">
      <a href="/my-blog/.">sun</a>
    </div>
  </div>
  <div class="page" id="mobile-nav-panel">
    <div class="container">
      <header class="site-nav">
      <div class="nav-content">
        <div class="logo">
          <a href="/my-blog/">sun</a>
        </div>
        <nav class="navbar">
          <ul>
            
              <li class="menu-item">
                <a href="/my-blog/" class="menu-item-link"><i class="iconfont icon-home"></i>首页</a>
              </li>
            
              <li class="menu-item">
                <a href="/my-blog/archives" class="menu-item-link"><i class="iconfont icon-archive"></i>归档</a>
              </li>
            
          </ul>
        </nav>
      </div>
</header>

      <div class="banner">
  <div class="show">
    <!-- <img src="/my-blog/" alt="banner"> -->
    <div class="banner-title">
      
        <div class="post-title">
          rem适配移动页面-js方法
            <div class="post-tags">
    		    
              <a class="tag-link" href="/my-blog/tags/rem/">rem</a>
            
    	      </div>
        </div>
      
    </div>
  </div>
</div>

      <main class="main"id="main">
          <article class="post">
  

  <header>
    <div class="post-title mobile-post-title">
      <h1>rem适配移动页面-js方法</h1>
        <div class="post-tags">
        
          <a class="tag-link" href="/my-blog/tags/rem/">rem</a>
        
        </div>
    </div>
    <div class="post-meta">
      <span class="post-time"><i class="iconfont icon-calendar"></i>2017-05-23</span>
      
      <!----------------------------------->
        
      <!----------------------------------->
    </div>
  </header>
  
  <div class="post-toc" id="post-toc">
    <h2 class="post-toc-title">目录</h2>
    <div class="post-toc-content">
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#meta标签设置"><span class="toc-text">meta标签设置</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#引入js"><span class="toc-text">引入js</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#此方法当设计稿为640时，rem-100px，如果某文字字体大小为32px，直接设置font-size-32rem；即可。"><span class="toc-text">此方法当设计稿为640时，rem=100px，如果某文字字体大小为32px，直接设置font-size:32rem；即可。</span></a></li></ol></li></ol>
    </div>
  </div>


  <div class="post-content">
    <h2 id="meta标签设置"><a href="#meta标签设置" class="headerlink" title="meta标签设置"></a>meta标签设置</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1,user-scalable=0&quot;&gt;</span><br></pre></td></tr></table></figure>
<a id="more"></a>
<h3 id="引入js"><a href="#引入js" class="headerlink" title="引入js"></a>引入js</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">(function(doc, win) &#123;</span><br><span class="line">            var docEl = doc.documentElement,</span><br><span class="line">                resizeEvt = &apos;orientationchange&apos; in window ? &apos;orientationchange&apos; : &apos;resize&apos;,</span><br><span class="line">                recalc = function() &#123;</span><br><span class="line">                    var clientWidth = docEl.clientWidth;</span><br><span class="line">                    if (!clientWidth) return;</span><br><span class="line">                    if (clientWidth &gt;= 640) &#123;</span><br><span class="line">                        docEl.style.fontSize = &apos;100px&apos;;</span><br><span class="line">                    &#125; else &#123;</span><br><span class="line">                        docEl.style.fontSize = 100 * (clientWidth / 640) + &apos;px&apos;;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;;</span><br><span class="line">            if (!doc.addEventListener) return;</span><br><span class="line">            win.addEventListener(resizeEvt, recalc, false);</span><br><span class="line">            doc.addEventListener(&apos;DOMContentLoaded&apos;, recalc, false);</span><br><span class="line">        &#125;)(document, window);</span><br></pre></td></tr></table></figure>
<h3 id="此方法当设计稿为640时，rem-100px，如果某文字字体大小为32px，直接设置font-size-32rem；即可。"><a href="#此方法当设计稿为640时，rem-100px，如果某文字字体大小为32px，直接设置font-size-32rem；即可。" class="headerlink" title="此方法当设计稿为640时，rem=100px，如果某文字字体大小为32px，直接设置font-size:32rem；即可。"></a>此方法当设计稿为640时，rem=100px，如果某文字字体大小为32px，直接设置font-size:32rem；即可。</h3>
  </div>
  <div class="post-footer">the end</div>
</article>

          
  <nav class="pagination post-nav">
    
    
      <a href="/my-blog/2017/04/15/码云pages服务搭建hexo个人博客/">
        <span class="next-post">码云pages服务搭建hexo个人博客<i class="iconfont icon-more"></i></span>
      </a>
    
  </nav>


          
  


      </main>
    </div>
    <footer>
      <div class="social-links">
        
          
            <a href="https://www.zhihu.com/people/qi-lu-kan-fei-ji/activities"><i class="iconfont icon-zhihu"></i></a>
          
        
          
            <a href="https://weibo.com/u/2833609101"><i class="iconfont icon-weibo"></i></a>
          
        
          
            <a href="https://gitee.com/syanbo"><i class="iconfont icon-github"></i></a>
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
          
        
      </div>
      
        <div class="quote">
          <p>Love all, trust a few, do wrong to none.——William Shakespeare</p>
        </div>
      
      <div class="copyright">
        <p>
          由 <a href="https://hexo.io/">Hexo</a> 强力驱动
          <span>|</span>
          主题 - <a href="https://github.com/wa-ri/hexo-theme-ztopic">ztopic</a
        </p>
        <p>
          <span>
          
          &copy;
          
            2018
          
          </span>
          <i class="iconfont icon-circle"></i>
          <span>sun</span>
        </p>
      </div>
</footer>

    <div class="back-to-top" id="back-to-top">
      <i class="iconfont icon-up"></i>
    </div>
  </div>
  <div id="mobile-nav">
  <nav id="mobile-nav-menu">
    
      <a href="/my-blog/" class="mobile-nav-link"><i class="iconfont icon-home"></i>首页</a>
    
      <a href="/my-blog/archives" class="mobile-nav-link"><i class="iconfont icon-archive"></i>归档</a>
    
    <div class="mobile-intro"><i class="iconfont icon-pen"></i>practice makes perfect</div>
  </nav>
</div>


  <script src="/my-blog/libs/jQuery/jquery-3.2.1.min.js"></script>
  <script src="/my-blog/libs/slideout/slideout.min.js"></script>
  
    <link rel="stylesheet" href="/my-blog/libs/fancybox/jquery.fancybox.css">
    <script src="/my-blog/libs/fancybox/jquery.fancybox.pack.js"></script>
  
  

  <script src="/my-blog/js/ztopic.js"></script>
</body>
</html>
